package com.bs.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.io.File;
import org.springframework.web.multipart.MultipartFile;

/*此类采用单例设计模式用于获取数据库连接*/
public class DBUtils {

	public final static String perfix="`";
	public final static String sufix="`";
	public static SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static SimpleDateFormat setPattern(String pattern) {
		try {
			simpleDateFormat.applyPattern(pattern);
		} catch (Exception e) {
			// TODO Auto-generated catch block
		}
		return simpleDateFormat;
	}
	public static SimpleDateFormat getSimpleDateFormat() {
		return simpleDateFormat;
	}
	public static String getPattern() {
		return simpleDateFormat.toPattern();
	}
	public static Timestamp geCurrentTimestamp() {
		return new Timestamp(System.currentTimeMillis());
	}
	public static String geCurrentFormatDateTime() {
		return simpleDateFormat.format(geCurrentTimestamp());
	}
/*输出sql语句*/
	public static void saySql(String method,String sql) {
		System.out.println(method+"\r\n   --->"+sql);
	}
	public static String basePathname = "E:\\imgs";
	public static String setFile(MultipartFile multipartFile) throws Exception {
		if (multipartFile!=null) {
			String originalFilename = multipartFile.getOriginalFilename();
			if (multipartFile != null && originalFilename != null &&(!originalFilename.trim().equals(""))&& originalFilename.length() > 0) {
				File newFile = new File(basePathname, originalFilename);
				multipartFile.transferTo(newFile);
				return originalFilename;
			} 
		}
		return null;
	}
}
